package com.coderman.utils.bean;

import net.sf.cglib.beans.BeanCopier;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by on 2017-10-17.
 *
 * @author: fanchunshuai
 * @version: V1.0
 * @Desc:
 */
public class CglibConvertService implements IConvert {


    @Override
    public <T, K> List<T> copyPropertities(Class<T> clazz, List<K> objList) throws Exception {
        List<T> descList = new LinkedList<T>() ;
        if(objList==null){
            return null;
        }
        for(K k : objList){
            descList.add(copyPropertity(clazz, k));
        }
        return descList;
    }

    @Override
    public <T> T copyPropertity(Class<T> clazz, Object orig) throws Exception {
        T t = clazz.newInstance();
        BeanCopier beanCopier = CachedBeanCopier.getBeanCopier(orig,t);
        beanCopier.copy(orig,t,null);
        return t;
    }
}
